﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SnowDAL;
using SnowEntity;
using Common.Expansion;

namespace Snow
{
    public partial class UUserDetail : System.Web.UI.Page
    {
        private string _uid = "";

        protected UserInfo info = new UserInfo();

        protected UserDetail detail = new UserDetail();

        protected UserLike like = new UserLike();

        private UserDAL _dal = new UserDAL();

        protected void Page_Load(object sender, EventArgs e)
        {
            _uid = Request.QueryString["uid"].ToString();

            if (!IsPostBack)
            {
                Initialize();
            }
        }

        private void Initialize()
        {
            info = _dal.GetUserInfo(_uid);

            detail = _dal.GetUserDetail(_uid);

            if (info.State != 0)
                like = _dal.GetUserLike(_uid);

            txtName.Text = detail.Name;

            this.txtContent.Text = detail.Content;

            this.txtLikeContent.Text = like.Content;

            this.txtPoint.Text = info.Point.Value.ToString();

            Title = string.Format("Detail-{0}-{1}", info.Login_Name, detail.Name);
        }

        protected void btnModify_Click(object sender, EventArgs e)
        {
            if (_dal.UpdateUserDetail(_uid, txtContent.Text, txtName.Text) == 1)
            {
                Page.Alert("修改成功");
                Initialize();
            }
            else
                Page.Alert("修改失败。。。。。。。。");
        }

        protected void btnLikeModify_Click(object sender, EventArgs e)
        {
            if (_dal.UpdateUserLikeContent(_uid, txtLikeContent.Text) == 1)
            {
                Page.Alert("修改成功");
                Initialize();
            }
            else
                Page.Alert("修改失败。。。。。。。。");

        }

        protected void btnModifyPoint_Click(object sender, EventArgs e)
        {
            if (_dal.UpdateUserPoint(_uid, txtPoint.Text) == 1)
            {
                Page.Alert("修改Point成功");
                Initialize();
            }
            else
                Page.Alert("修改Point失败。。。。。。。。");
        }
    }
}